package com.wanmait.hotelManage.webservlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wanmait.hotelManage.dao.CommentDAO;
import com.wanmait.hotelManage.dao.HotelCommentDAO;
import com.wanmait.hotelManage.vo.HotelComment;
import com.wanmait.hotelManage.vo.Pager;
import com.wanmait.hotelManage.vo.Userinfo;

@WebServlet("/CommentServlet")
public class CommentServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		if("list".equals(action)) {
			this.list(request, response);
		}else if("initTwo".equals(action)) {
			this.initTwo(request, response);
		}
	}
	public void initTwo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	Integer id=Integer.parseInt(request.getParameter("id"));
	Pager pager=new Pager();
	pager.setPageNo(id);
	pager.setPageSize(6);
	int rows=HotelCommentDAO.getHotelcommentdao().getrows();
	pager.setPageCount(rows);
	List<HotelComment>hotelComments=HotelCommentDAO.getHotelcommentdao().findAll(pager);
	request.setAttribute("pager", pager);
	request.setAttribute("hotelComments", hotelComments);
	request.getRequestDispatcher("/commentInitTwo.jsp").forward(request, response);
	}
	//列出第一页评论
	public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Pager pager=new Pager();
		pager.setPageNo(1);
		pager.setPageSize(6);
		int rows=HotelCommentDAO.getHotelcommentdao().getrows();
		pager.setPageCount(rows);
		List<HotelComment>hotelComments=HotelCommentDAO.getHotelcommentdao().findAll(pager);
//		for(int i=0;i<hotelComments.size();i++) {
//			System.out.println(hotelComments.get(i).getContent());
//		}
		request.setAttribute("pager", pager);
		request.setAttribute("hotelComments", hotelComments);
		request.getRequestDispatcher("/comment.jsp").forward(request, response);
	}

}
